//
//  HomeTableViewCell.m
//  GentlemanAnime
//
//  Created by dlios on 15-6-29.
//  Copyright (c) 2015年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "HomeTableViewCell.h"
#import "DownloadSingletonTool.h"

@implementation HomeTableViewCell

- (void)dealloc {
    [_titleLabel release];
    [_statusSwitch release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        self.titleLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.statusSwitch = [[UISwitch alloc] init];
        [self.contentView addSubview:self.statusSwitch];
        [self.statusSwitch addTarget:self action:@selector(switchClick) forControlEvents:UIControlEventValueChanged];
        [_statusSwitch release];
        
    }
    return self;
}

- (void)switchClick {
    if (self.statusSwitch.on) {
        [DownloadSingleton shareDownloadSingleton].canSee = 1;
    } else {
        [DownloadSingleton shareDownloadSingleton].canSee = 2;
    }
    NSArray *sandBox = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *SandBoxPath = sandBox[0];
    NSString *canSeeSandBoxPath = [SandBoxPath stringByAppendingPathComponent:@"canSee.txt"];
    NSString *str = [NSString stringWithFormat:@"%d",[DownloadSingleton shareDownloadSingleton].canSee];
    [str writeToFile:canSeeSandBoxPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleLabel.frame = CGRectMake(15, 0, self.contentView.frame.size.width / 2, self.contentView.frame.size.height);
    self.statusSwitch.frame = CGRectMake(self.contentView.frame.size.width - 55, self.contentView.frame.size.height / 2 - 15.5, 30, 15);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
